package com.smarthome.core.operationservicemanager.impl;

import java.util.ArrayList;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.smarthome.base.service.ShAreaProvinceService;
import com.smarthome.base.service.ShExpressFeeService;
import com.smarthome.core.operationservicemanager.ExpressFeeService;
import com.smarthome.domain.bean.ShAreaProvince;
import com.smarthome.domain.bean.ShExpressFee;
import com.smarthome.domain.vo.boss.DataGrid;
import com.smarthome.domain.vo.boss.PageHelper;
import com.smarthome.domain.vo.boss.Tree;
/**
 * 
* @ClassName: ExpressFeeServiceImpl
* @Description: 快递费service接口实现类
* @author cyj
* @date 2016年4月20日 上午10:56:30
*
 */
@Service("expressFeeService")
public class ExpressFeeServiceImpl implements ExpressFeeService {


	@Resource
	private ShExpressFeeService shExpressFeeService;
	
	@Resource
	private ShAreaProvinceService shAreaProvinceService;
	
	@Override
	public ShExpressFee getById(Long id) {
		return shExpressFeeService.getDetailById(id);
	}

	@Override
	public DataGrid qeuryDataGrid(ShExpressFee expressFee, PageHelper page) {
		return shExpressFeeService.qeuryDataGrid(expressFee, page);
	}

	@Override
	public Integer saveOrUpdate(ShExpressFee expressFee) {
		return shExpressFeeService.saveOrUpdate(expressFee);
	}

	@Override
	public Integer delete(Long id) {
		return shExpressFeeService.deleteByIds(id);
	}

	

	@Override
	public List<ShExpressFee> getList(ShExpressFee expressFee) {
		return shExpressFeeService.getDetailList(expressFee);
	}

	@Override
	public List<Tree> getExpressFeeProvince(Long expressId) {
		
		List<Tree> provinceTree = new ArrayList<Tree>();
		Tree root = new Tree(0l, "快递区域");
		provinceTree.add(root);
		if(expressId == null) {
			return provinceTree;
		}
		ShAreaProvince shAreaProvince = new ShAreaProvince();
		shAreaProvince.addQueryData("expressId", expressId);
		List<ShAreaProvince> provinceList = shAreaProvinceService.getExpressFeeProvince(shAreaProvince);
		if(provinceList != null) {
			List<Tree> provinces = new ArrayList<Tree>();
			int length = provinceList.size();
			for(int i = 0;i < length;i++) {
				provinces.add(new Tree(provinceList.get(i).getId(), provinceList.get(i).getProvinceName(), 0l));
			}
			root.setChildren(provinces);
		}
		return provinceTree;
	}

	@Override
	public Integer add(ShExpressFee... t) {
		return shExpressFeeService.insert(t);
	}

}
